home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Sprite 1984 - 1993
/
Sprite 1984 - 1993.iso
/
src
/
lib
/
c
/
etc
/
RCS
/
ldexp.c,v
< prev
next >
Wrap
Text File
|
1991-12-03
|
3KB
|
117 lines
head 1.2;
branch ;
access ;
symbols sprited:1.2.1;
locks ; strict;
comment @ * @;
1.2
date 91.12.02.21.51.16; author kupfer; state Exp;
branches 1.2.1.1;
next 1.1;
1.1
date 91.12.02.21.50.38; author kupfer; state Exp;
branches ;
next ;
1.2.1.1
date 91.12.02.21.51.35; author kupfer; state Exp;
branches ;
next ;
desc
@Source for ldexp() library routine.
@
1.2
log
@Fix file name in header comment.
@
text
@/*
* ldexp.c --
*
* Source code for the ldexp library function.
*
* Copyright 1988 Regents of the University of California
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
* fee is hereby granted, provided that the above copyright
* notice appear in all copies. The University of California
* makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without
* express or implied warranty.
*/
#ifndef lint
static char rcsid[] =
"$Header: /sprite/src/lib/c/etc/RCS/ldexp.c,v 1.1 91/12/02 21:50:38 kupfer Exp Locker: kupfer $ SPRITE (Berkeley)";
#endif not lint
#include <stdio.h>
#include "errno.h"
/* Largest signed long int power of 2 */
#define MAXSHIFT (8 * sizeof(long) - 2)
#define MAXFLOAT 1.7e308
double ldexp(value, exp)
double value;
int exp;
{
extern double frexp();
int old_exp;
if (exp == 0 || value == 0.0) /* nothing to do for zero */
return (value);
(void) frexp(value, &old_exp);
if (exp > 0) {
if (exp + old_exp > 1023) { /* overflow */
errno = ERANGE;
return (value < 0 ? -MAXFLOAT : MAXFLOAT);
}
for ( ; exp > MAXSHIFT; exp -= MAXSHIFT)
value *= (1L << MAXSHIFT);
return (value * (1L << exp));
}
if (exp + old_exp < -1023) { /* underflow */
errno = ERANGE;
return (0.0);
}
for ( ; exp < -MAXSHIFT; exp += MAXSHIFT)
value *= 1.0/(1L << MAXSHIFT); /* mult faster than div */
return (value / (1L << -exp));
}
@
1.2.1.1
log
@Initial branch for Sprite server.
@
text
@d18 1
a18 1
"$Header: /sprite/src/lib/c/etc/RCS/ldexp.c,v 1.2 91/12/02 21:51:16 kupfer Exp $ SPRITE (Berkeley)";
@
1.1
log
@Initial revision
@
text
@d2 1
a2 1
* modf.c --
d18 1
a18 1
"$Header: ldexp.c,v 1.1 88/09/10 16:39:34 mendel Exp $ SPRITE (Berkeley)";
@